<template>
  <scroll-view
    @scrolltolower="handleToLower"
    class="recommend_view"
    scroll-y
    v-if="recommends.length > 0"
  >
    <!-- 推荐 开始 -->
    <view class="recommend_wrap">
      <navigator
        class="recommend_item"
        v-for="item in recommends"
        :key="item.id"
        :url="`/pages/album/index?id=${item.target}`"
      >
        <image mode="widthFix" :src="item.thumb" />
      </navigator>
    </view>
    <!-- 推荐 结束 -->

    <!-- 月份 开始 -->
    <view class="monthes_wrap">
      <view class="monthes_title">
        <view class="monthes_title_info">
          <view class="monthes_info">
            <text>{{ monthes.DD }} /</text>
            {{ monthes.MM }} 月
          </view>
          <view class="monthes_text">{{ monthes.title }}</view>
        </view>
        <!-- <view class="months_title_more">更多 ></view> -->
      </view>
      <view class="monthes_content">
        <view
          class="monthes_item"
          v-for="(item, index) in monthes.items"
          :key="item.id"
        >
          <go-detail :list="monthes.items" :index="index">
            <image
              mode="aspectFill"
              :src="item.thumb + item.rule.replace('$<Height>', 360)"
            />
          </go-detail>
        </view>
      </view>
    </view>
    <!-- 月份 结束 -->

    <!-- 热门 开始 -->
    <view class="hots_wrap">
      <view class="hots_title">
        <text>热门</text>
      </view>
      <view class="hots_content">
        <view class="hot_item" v-for="(item, index) in hots" :key="item.id">
          <go-detail :list="hots" :index="index">
            <image :src="item.thumb" mode="widthFix" />
          </go-detail>
        </view>
      </view>
    </view>
    <!-- 热门 结束 -->
  </scroll-view>
</template>

<script>
import moment from "moment";
import goDetail from "@/components/goDetail";
export default {
  components: {
    goDetail,
  },
  data() {
    return {
      // 推荐模块
      recommends: [],
      // 月份模块
      monthes: {},
      // 热门列表
      hots: [],
      // 请求参数
      params: {
        limit: 30,
        order: "hot",
        skip: 0,
      },
      // 是否还有下一页
      hasMore: true,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    //获取接口数据
    getList() {
      // 接口文档
      // https://www.showdoc.com.cn/414855720281749?page_id=3678621017219602
      this.request({
        url: "http://157.122.54.189:9088/image/v3/homepage/vertical",
        data: this.params,
        method: "GET",
      }).then((result) => {
        // console.log(result);
        // 判断还有没有下一页数据
        if (result.res.vertical.length === 0) {
          this.hasMore = false;
          return;
        }

        //第一次请求数据，之后不变
        if (this.recommends.length === 0) {
          // 推荐模块
          this.recommends = result.res.homepage[1].items;
          // 月份模块
          this.monthes = result.res.homepage[2];
          // 月份格式
          this.monthes.MM = moment(this.monthes.stime).format("MM");
          this.monthes.DD = moment(this.monthes.stime).format("DD");
        }
        // 热门列表
        this.hots = [...this.hots, ...result.res.vertical];
      });
    },
    // 滚动条触底事件
    handleToLower() {
      if (this.hasMore) {
        this.params.skip += this.params.limit;
        this.getList();
      } else {
        uni.showToast({
          title: "没有数据了",
          icon: "none",
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.recommend_view {
  height: calc(100vh - 36px);
}
.recommend_wrap {
  display: flex;
  flex-wrap: wrap;
  .recommend_item {
    width: 50%;
    border: 5rpx solid #fff;
  }
}
.monthes_wrap {
  .monthes_title {
    display: flex;
    justify-content: space-between;
    padding: 20rpx;
    .monthes_title_info {
      font-weight: 600;
      display: flex;
      .monthes_info {
        color: $color;
        font-size: 30rpx;
        text {
          color: $color;
          font-size: 36rpx;
        }
      }

      .monthes_text {
        font-size: 34rpx;
        color: #666;
        margin-left: 30rpx;
      }
    }

    .months_title_more {
      font-size: 24rpx;
      color: $color;
    }
  }

  .monthes_content {
    display: flex;
    flex-wrap: wrap;
    .monthes_item {
      width: 33.33%;
      border: 5rpx solid #fff;
    }
  }
}
.hots_wrap {
  .hots_title {
    padding: 20rpx;
    text {
      border-left: 20rpx solid $color;
      padding-left: 20rpx;
      font-size: 34rpx;
      font-weight: 600;
    }
  }

  .hots_content {
    display: flex;
    flex-wrap: wrap;
    .hot_item {
      width: 33.33%;
      border: 5rpx solid #fff;
      img {
      }
    }
  }
}
</style>
